package com.imooc.myo2o.dao.split;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class DynamicDataSourceHolder {

	private static ThreadLocal<String> contextHolder=new ThreadLocal<>();

	public static final String DB_MASTER = "master";
	public static final String DB_SLAVE = "slave";

	public static Object getDbType() {
		String db = contextHolder.get();
		if (db == null) {
			db = DB_MASTER;
		}
		return db;
	}

	public static void setDbType(String str) {
		log.debug("所使用的数据源为" + str);
		contextHolder.set(str);
	}

	public static void clearDbType(){
		contextHolder.remove();
	}

}
